/**
 * jims
 */
package com.jims.master.modules.csm.service;

import com.jims.master.common.persistence.Page;
import com.jims.master.common.service.CrudService;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.modules.csm.dao.ExpDetailsDao;
import com.jims.master.modules.csm.entity.ExpDetails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 消耗理信息Service
 * @author DT
 * @version 2017-03-15
 */
@Service
@Transactional(readOnly = true)
public class ExpDetailsService extends CrudService<ExpDetailsDao, ExpDetails> {
	@Autowired
	private ExpDetailsDao expDetailsDao;
	public ExpDetails get(String id) {
		return super.get(id);
	}
	
	public List<ExpDetails> findList(ExpDetails expDetails) {
		return super.findList(expDetails);
	}
	
	public Page<ExpDetails> findPage(Page<ExpDetails> page, ExpDetails expDetails) {
		return super.findPage(page, expDetails);
	}
	
	@Transactional(readOnly = false)
	public int save(ExpDetails expDetails) {
		int i=0;
		if(StringUtils.isNotBlank(expDetails.getId())){
			expDetails.preUpdate();
			i=dao.update(expDetails);
		}
		else if(StringUtils.isNotBlank(expDetails.getExpInfoId())){
			ExpDetails expDetails1=expDetailsDao.findByexpInfoId(expDetails);
			if (expDetails1!=null){
				expDetails.preUpdate();
				i=dao.update(expDetails);
			}
			else {
				expDetails.preInsert();
				expDetails.updateOrgId();
				i=dao.insert(expDetails);
			}
		}
		return i;
	}
	@Transactional(readOnly = false)
	public int delete(ExpDetails expDetails) {
		return super.delete(expDetails);
	}

	public ExpDetails findByexpInfoId(ExpDetails expDetails){
		return expDetailsDao.findByexpInfoId(expDetails);
	}
}